<template>
  <div class="consumer-page activity-list-page">
    <el-breadcrumb class="breadcrumb page-title" separator="/">
      <el-breadcrumb-item :to="{ path: '/propertyIndex'}">Property</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="container-padding">
      <!--serchBox-->
      <div class="search-box">
        <el-form :inline="true" label-position="top" :model="form" size="mini" ref="ruleForm"
                 class="demo-ruleForm main-search-box">
          <el-row>
            <!--Status-->
            <el-form-item label="Status" style="margin-right: 10px">
              <el-select style="width: 140px" v-model="form.status" placeholder="">
                <el-option v-for="i in statusOption" :key="i.value" :label="i.label" :value="i.value"></el-option>
              </el-select>
            </el-form-item>
            <!--name-->
            <el-form-item label="Name" style="width: 250px;">
              <el-input v-model="form.name" placeholder=""></el-input>
            </el-form-item>
            <!--search-->
            <el-form-item style="margin-top: 37px">
              <el-button @click="$router.back(-1)" type="info" style="width:80px;margin-left: 30px;">Cancel</el-button>
            </el-form-item>
            <el-form-item style="margin-top: 37px;">
              <el-button @click="getList" type="primary" style="width:80px">Search</el-button>
            </el-form-item>
            <!--<el-form-item style="margin-top: 37px;">-->
              <!--<el-button @click="$router.push('./propertyNew')" type="success" style="width:80px">New</el-button>-->
            <!--</el-form-item>-->
          </el-row>
        </el-form>
      </div>
      <!--list-->
      <div class="list-items-box">
        <el-table
          :data="tableData"
          v-loading="tableLoading"
          border
          ref="singleTable"
          highlight-current-row
          @current-change="handleCurrentChange"
          style="width: 100%"
          :row-class-name="tableRowClassName"
        >
          <!--edit-->
          <el-table-column
            prop="" label="Edit"
            align="center"
            width="100">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="propertyEdit(scope.row.id)">Edit</el-button>
            </template>
          </el-table-column>
          <!--ID-->
          <el-table-column
            prop="id"
            label="ID"
            align="center"
            min-width="80">
          </el-table-column>
          <!--status-->
          <el-table-column
            prop="status"
            label="Status"
            align="center"
            min-width="140">
            <template slot-scope="scope">
              <div>{{getStatus(scope.row.status)}}</div>
            </template>
          </el-table-column>
          <!--english name-->
          <el-table-column
            prop="name"
            label="English Name"
            align="center"
            min-width="200">
            <template slot-scope="scope">
              <div>{{unicodeTozawgyi(scope.row.name)}}</div>
            </template>
          </el-table-column>
          <!--mm name-->
          <el-table-column
            prop="nameMm"
            label="MM Name"
            align="center"
            min-width="250">
            <template slot-scope="scope">
              <div>{{unicodeTozawgyi(scope.row.nameMm)}}</div>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <div class="block" style="margin-top: 15px;text-align: center;">
          <el-pagination
            @size-change="handleChangeSize"
            @current-change="handleChangePage"
            :current-page="pageData.pageNum"
            :page-size="pageData.pageSize"
            :page-sizes="[10, 20, 50, 100, 500]"
            :page-count="pageInfo.totalPages"
            :total="pageInfo.totalCount"
            layout="total, prev, pager, next, jumper, sizes">
          </el-pagination>
        </div>
      </div>
    </div>

  </div>
</template>

<script>

  import {getPropertyList} from '../../api/guc_api.js'

  export default {
    name: 'shopUser',
    data() {
      return {
        form: {
          status: '',
          name: ''
        },
        statusOption: [
          {
            label: 'Active',
            value: '1'
          },
          {
            label: 'Deleted',
            value: '0'
          }
        ],
        pageData: {
          pageNum: 1,
          pageSize: 10,
        },
        pageInfo: {
          totalCount: 0,
          totalPages: 0
        },
        tableLoading: false,
        tableData: [],
        // 当前行
        currentRow: null,
      }
    },
    methods: {
      // 用来控制表格行点击选中状态
      handleCurrentChange(val) {
        this.currentRow = val;
      },
      //用来控制单双行样式
      tableRowClassName({row, rowIndex}) {
        if (rowIndex % 2 === 1) {
          return 'odd-row';
        }
        else if (rowIndex % 2 === 0) {
          return 'even-row';
        }
        return '';
      },
      handleChangeSize(val) {
        this.pageData.pageSize = parseInt(val)
        this.pageData.pageNum = 1
        this.getList()
      },
      handleChangePage(val) {
        this.pageData.pageNum = val
        this.getList()
      },
      //跳转到property编辑页面
      propertyEdit(id) {
        this.$router.push({
          path: '/propertyEdit',
          query: {
            id: id
          }
        })
      },
      // 状态格式化
      getStatus(value) {
        if (value == 0) {
          return 'Deleted';
        }
        else if (value == 1) {
          return 'Active';
        }
      },
      //对表格中的内容进行unicode转交集
      unicodeTozawgyi(value) {
        if (value) {
          return this.$translateLang(value, 'unicodeTozawgyi') || ''
        } else {
          return value;
        }
      },
      // message alert 用于前端错误提示信息
      messageToastErr(msg) {
        this.$message({
          showClose: true,
          message: msg,
          duration: 5000,
          type: 'error'
        })
      },
      getList(pageNum) {
        window.scrollTo(0, 0)
        this.tableLoading = true;
        if (pageNum == 1) {
          this.pageData.pageNum = 1;
        }
        if (this.form.name) {
          this.form.name = this.$translateLang(this.form.name || '', 'zawgyiTounicode') || ''
        }
        getPropertyList(Object.assign(this.form, this.pageData))
          .then((res) => {
            this.tableData = res.data.object.list || []
            // 分页信息配置
            this.pageInfo.totalPages = res.data.object.pages
            this.pageInfo.totalCount = res.data.object.total
            this.tableLoading = false;
          })
          .catch((e) => {
            this.tableLoading = false;
          })
      },
    },
    mounted() {
      this.getList(1)
    }
  }
</script>


<style>
  .page-title {
    padding: 20px 40px;
    border-bottom: 1px solid #e6e6e6;
    font-size: 20px !important;
  }

  .breadcrumb {
    margin-bottom: 20px;
  }

  .page-title {
    padding: 20px 40px;
    border-bottom: 1px solid #e6e6e6;
    font-size: 20px;
  }

  .search-box {
    position: relative;
    /*padding-top: 20px;*/
    border-bottom: 1px solid #eee;
  }

  .more-box, .list-items-box {
    padding-top: 20px;
    padding-bottom: 10px;
  }

  .list-items-box .el-form--inline.el-form--label-top .el-form-item__content {
    display: inline-block;
  }

  .container-padding {
    padding: 0 40px;
  }

  .new-user-dialog .el-form-item {
    margin-bottom: 0 !important;
  }

  .activity-list-page .el-checkbox + .el-checkbox {
    margin-left: 0 !important;
    margin-right: 30px !important;
  }
</style>
